package com.xy.mvvmdemo

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter

/**
 * @ClassName MyFragmentAdapter
 * @Author xy
 * @Date 2021/7/19 16:15
 * @Description  Viewpager 适配器
 */
@Suppress("DEPRECATION")
class MyFragmentAdapter(fm:FragmentManager):FragmentStatePagerAdapter(fm) {

    var listTitles = arrayListOf<String>()
    var listFragments = arrayListOf<Fragment>()

    constructor(fm: FragmentManager,listTitles: MutableList<String>,listFragments:MutableList<Fragment>):this(fm)
    override fun getCount(): Int {
        return listTitles.size
    }

    override fun getItem(position: Int): Fragment {
        return listFragments[position]
    }

    override fun getItemPosition(`object`: Any): Int {
        return POSITION_NONE // 如果页面数据发生变化，需要重写改方法
    }

}